package common;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;

public class HibernateUtil {
	public static SessionFactory getSessionFactory() {
	StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure("hibernate.cfg.xml").build();  
	//2. 根据服务注册类创建一个元数据资源集，同时构建元数据并生成应用一般唯一的的session工厂  
	SessionFactory sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); 
	return sessionFactory;
	}
	public static Session openSession() {
		return getSessionFactory().openSession();
	}

}